//
//  CustomDatePickerViewController.m
//  RainbowFM
//
//  Created by jv on 14-12-7.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "CustomDatePickerViewController.h"
#import "UserModel.h"

@interface CustomDatePickerViewController ()

@end

@implementation CustomDatePickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = @"选择日期";
    UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"确定"
                                                                     style:UIBarButtonItemStyleBordered
                                                                    target:self
                                                                    action:@selector(submitAction)];
    submitButton.tintColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = submitButton;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)navBackAction
{
    if ([_delegate respondsToSelector:@selector(didDatePickedWithCtrl:date:)]) {
        NSString *dateStr = [NSDate stringFromDate:_picker.date withFormat:@"yyyy-MM-dd"];
        [_delegate didDatePickedWithCtrl:self date:dateStr];
    }
    
    [super navBackAction];
}


-(void)submitAction{
    NSString *dateStr = [NSDate stringFromDate:_picker.date withFormat:@"yyyy年MM月dd日"];
    [[UserModel sharedModel] editUserProfileBirthday:dateStr reuslt:^(BOOL success) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
